package com.code.day20;

import java.io.FileOutputStream;
import java.io.IOException;

public class Demo01FileOutputStream {
    public static void main(String[] args) throws IOException {
        method1();
        method2();
        method3();
        method4();
    }


    /**
     * 一次写一个字节
     * @throws IOException
     */
    public static void method1() throws IOException {
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\java-code\\java-full-stack\\01-java-base\\src\\com\\code\\day20\\file\\demo1.txt");
        fileOutputStream.write(97);
        fileOutputStream.close();
    }

    /**
     * 一次写一个字节组
     * @throws IOException
     */
    public static void method2() throws IOException {
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\java-code\\java-full-stack\\01-java-base\\src\\com\\code\\day20\\file\\demo1.txt");
        byte[] bytes = {97,98,99,100};
        fileOutputStream.write(bytes);
        fileOutputStream.close();
    }

    /**
     * 一次写一个字节数组的一部分
     * @throws IOException
     */
    public static void method3() throws IOException {
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\java-code\\java-full-stack\\01-java-base\\src\\com\\code\\day20\\file\\demo1.txt");
        byte[] bytes = {97,98,99,100};
        fileOutputStream.write(bytes,1,3);
        fileOutputStream.close();
    }

    /**
     * 一次写一个字节的汉字
     * @throws IOException
     */
    public static void method4() throws IOException {
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\java-code\\java-full-stack\\01-java-base\\src\\com\\code\\day20\\file\\demo1.txt");
        fileOutputStream.write("你好".getBytes());
        fileOutputStream.close();
    }

}
